package com.qf.controller;

import com.qf.pojo.Fangxing;
import com.qf.pojo.Xiadan;
import com.qf.pojo.XiadanDTO;
import com.qf.service.XiadanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/xiadan")
public class XiadanController {
    @Autowired
    private XiadanService xiadanService;

    /*显示下单页面*/
    @RequestMapping("/selectXiadan")
    @ResponseBody
    XiadanDTO selectXiadan(Fangxing fangxing) {
        XiadanDTO xiadanDTO1 = xiadanService.selectXiadan(fangxing);
        return xiadanDTO1;
    }

    /*添加下单*/
    @RequestMapping("/addXiadan")
    @ResponseBody
    Integer addXiadan(Xiadan xiadan) {
        xiadanService.addXiadan(xiadan);
        return 1;
    }

    /*根据用户id查询所有下单记录*/
    @RequestMapping("/selectAllById/{id}")
    @ResponseBody
    List<Xiadan> selectAllById(@PathVariable Integer id) {
        List<Xiadan> xiadans = xiadanService.selectAllById(id);
        return xiadans;
    }

    /*后台---------------------------*/
    /*显示所有下单记录*/
    @RequestMapping("/selectAll")
    String selectAll(Model model) {
        List<Xiadan> xiadans = xiadanService.selectAll();
        model.addAttribute("xiadanlist", xiadans);
        return "xiadanlist";
    }
}
